<!doctype html>
<html>
<head>
	<meta charset="UTF-8">
	<title></title>
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<link href="../css/mui.min.css" rel="stylesheet" />
	<link rel="stylesheet" href="../css/setting.css" />
</head>

<body class="white">
	<div class="mui-content login" id="vueMain">
		<div class="mui-content-padded">
			<div class="back-icon mui-action-back"><img src="../icon/gray-back.png" class=" " alt="" /></div>
	    		<div class="logobox">
	    			<div class="logobsd">
	    				<!--<img src="" alt="" />-->
	    				<div class="turu"></div>
	    				<div class="turu2"></div>
	    				
	    			</div>
	    		</div>
	    		<div class="forms">
			    	<div class="inputBox">
			    		<input type="number" name="" v-model="sendData.mobile" placeholder="您的手机号码" class="userIcon" />
			    	</div>
			    	<div class="inputBox">
			    		<input type="password" name="" v-model="sendData.password" placeholder="" class="pwdIcon2" />
			    	</div>
		    </div>
		    <div class="mui-content-padded" style="margin-top: 20px;">
		   		<button type="button" class="bexta-btn bexta-btn-red mui-btn mui-btn-block " id="loginBtn"  >登录</button>
		   </div>
		   <div class="mui-clearfix nb" style="padding:0 10px;">
		   		<div class="mui-pull-right link" _id="forget" _title="忘记密码" _href="forget.html" _extras="type=forget">忘记密码</div>
		   		<div class="mui-pull-left link" _id="register" _title="注册" _href="register.html">注册</div>
		   </div>
	    </div>
	</div>
	<div class="party">
		<div class="title"><span>第三方登录</span></div>
		<div class="party-lev">
			<!--<a class="qq"><img src="../icon/qq.png" /></a>-->
			<a id="weixin"><img src="../icon/wechat.png" /></a>
			<!--<a><img src="../icon/weibo.png" /></a>-->
		</div>
	</div>
<script src="../js/mui.js"></script>
<script src="../js/vue.min.js"></script>
<script src="../js/bexta.js"></script>
<script type="text/javascript">
	var apps;
	mui.init();
	 mui.ready(function () {
	 	  document.querySelector('.login').style.paddingTop = bexta.getStatusHeight() + 'px';
	 });
	mui.plusReady(function () {
		initVue();	
	    bexta.toggleStatus(plus.webview.currentWebview());
	});
	function initVue(red){
		apps = new Vue({
			el:'#vueMain',
			data:{
				sendData:{
					mobile:'',
					password:''
				}
			},
			mounted:function(){
				document.querySelector('.turu').classList.add('active');
//				document.querySelector('.logobox img').src = red.web_logo;
				initEvent();
			}
		});
	}
	function initEvent(){
		document.querySelector('#loginBtn').addEventListener('tap', function(){
			if( check.phone(apps.sendData.mobile) && apps.sendData.password.length > 5 && apps.sendData.password.length <= 16 ){
				bexta.ajax('' + api.login, function(res){
					//设定用户默认值
					res.name = res.name?res.name:res.mobile;
					res.head_img = res.head_img?res.head_img:'../icon/rads.png';
					if( plus.webview.currentWebview().refresh == 'refresh' ){
						mui.fire(bexta.parentsView(), 'LoginRefresh');
					}
					bexta.setStorage(USER, res);
					mui.back();
				},{data:apps.sendData});
			}else{
				mui.toast("手机或密码错误");
			}
		});
		//第三方登录
		var oauth = {};
		plus.oauth.getServices(function(res){
			for( var i in res ){
				if( res[i].id == 'weixin' ){
					oauth[res[i].id] = res[i];
				}
			}
		});
		function getUserInfor(ouser, result){
			ouser.getUserInfo(function(){
				bexta.ajax(api.third_login, function(res){
//					alert( JSON.stringify(res) )
					if( res.uid == 0 ){
						bexta.openWithTitle({
							id:'bindMobile',
							url:'bindMobile.html', 
							extras:{user:ouser}
						},{
							title:{
								text:"绑定手机号"
							}
						});
					}else{
						//登录
						bexta.setStorage(USER, res);
						mui.back();
					}
					ouser.logout(function(){});
				}, {data:{type:ouser.id, third_key:ouser.userInfo.openid}})


			}, function (){
				mui.toast('登录失败2');
			})
		}
		mui('.party-lev').on('tap', 'a', function(){
			var o = oauth[this.id];
			if( o ){
				o.login(function(result){
//					alert( JSON.stringify(result) );
					getUserInfor(o, result);
				}, function(err){
					mui.toast('无法获取信息');
				});
			}
		});
		
		
		
		 
	}
</script>
</body>
</html>